package com.csdj.t309tgspringboot.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

@Service("redisService")
public class RedisService {
    @Resource
    private RedisTemplate<String,Object> objectRedisTemplate;

    private Logger logger = LoggerFactory.getLogger("RedisService");

    public void setObject(String key,Object obj){
        objectRedisTemplate.opsForValue().set(key,obj);
    }

    public <T> T getObject1(String key,Class<? extends T> clazz){
        Object o = objectRedisTemplate.opsForValue().get(key);
        if(o==null)return null;
        if(clazz.isInstance(o)){
            return (T)o;
        }
        logger.error("{}的值不是{}的实例",key,clazz.getName());
        return null;
    }

    public void sub(String channel){

    }
}
